///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Precompiled Header

#include "Math\LaborMathInclude.h"

NAMESPACE_LABOR3D_BEGIN
CLCylinder::CLCylinder( const CLPoint &p, const CLPoint &d, float r ) :
m_axisPos(p), 
m_axisDir(d), 
m_radius (r) 
{
}

CLCylinder::CLCylinder( const CLCylinder &c ) :
m_axisPos(c.m_axisPos), 
m_axisDir(c.m_axisDir), 
m_radius (c.m_radius )

{
}

CLCylinder::CLCylinder( )
{
}

CLCylinder::~CLCylinder()
{
}


void CLCylinder::getCenter(CLPoint &center) const
{
	center = m_axisPos + m_axisDir * .5;
}


float CLCylinder::getScalarVolume(void) const
{
	//	return isEmpty() ? 0.0f : (m_radius * m_radius * Pi * m_axisDir.length());
	return true;
}

/*! gives the boundaries of the volume */

void CLCylinder::getBounds( CLPoint &min, CLPoint &max ) const
{
	// this is rather simpleminded, but good enough for now

	if(m_axisDir[0] < 0)
	{
		min[0] = m_axisPos[0] + m_axisDir[0] - m_radius;
		max[0] = m_axisPos[0] - m_axisDir[0] + m_radius;
	}
	else
	{
		min[0] = m_axisPos[0] - m_axisDir[0] - m_radius;
		max[0] = m_axisPos[0] + m_axisDir[0] + m_radius;
	}

	if(m_axisDir[1] < 0)
	{
		min[1] = m_axisPos[1] + m_axisDir[1] - m_radius;
		max[1] = m_axisPos[1] - m_axisDir[1] + m_radius;
	}
	else
	{
		min[1] = m_axisPos[1] - m_axisDir[1] - m_radius;
		max[1] = m_axisPos[1] + m_axisDir[1] + m_radius;
	}

	if(m_axisDir[2] < 0)
	{
		min[2] = m_axisPos[2] + m_axisDir[2] - m_radius;
		max[2] = m_axisPos[2] - m_axisDir[2] + m_radius;
	}
	else
	{
		min[2] = m_axisPos[2] - m_axisDir[2] - m_radius;
		max[2] = m_axisPos[2] + m_axisDir[2] + m_radius;
	}
}


bool CLCylinder::intersect(const CLCylinder &cylinder) const
{
	return flIntersect(*this, cylinder);
}

bool CLCylinder::intersect( const CLSphere &sphere ) const
{
	return flIntersect( *this, sphere );
}

bool CLCylinder::intersect( const CLAABB &box ) const
{
	return flIntersect( *this, box );
}

NAMESPACE_LABOR3D_END